<?php
	$new_user = "";
	$new_mac = "";
	$skn = "";
	$msg = "";
	$error = "";

    if (isset($_REQUEST['user_name']) && 
        isset($_REQUEST['mac_address']) &&
        $_REQUEST['user_name'] != "" &&
        $_REQUEST['mac_address'] != "") 
    {

        global $db_manager;
        $new_user = $_REQUEST['user_name'];
        $new_mac = $_REQUEST['mac_address'];
        
        $xdenegats = new x_denegats($db_manager);
        
        // Check MAC address
        if ($xdenegats->is_valid_mac($new_mac)) {
            
            if ($xdenegats->add_denegat($new_user, $new_mac) > 0) {
                $msg = $labels["LBL_MAC_ADDED"];
                $skn = "showmessage";
                //Firewall rules should be restarted
                $xadmin = new x_admin($db_manager);
                $xadmin->set_reboot_mark();
                // Log action
                $xlog = new x_log($db_manager);
                $xlog->add_msg(sprintf($log_msg["LOG_MSG_ADDMAC"], $new_mac, $new_user));
            } else {
                $msg = $db_manager->db_error();
                $skn = "addmac";           
            }
            
        } else {
            $msg = $labels["LBL_WRONG_MAC"];
            $skn = "addmac";
        }       
        
    } else {
        $skn = "addmac";
        $msg = "";
    }

    $Skinner=new Skinner();
    $Skinner->setSkin($skins_path.$skn);
    $Skinner->registerVariable("files_path", $files_path);
    $Skinner->registerVariable("admin_root", $admin_root);    
    $Skinner->registerVariable("message", $msg);
    $Skinner->registerVariable("lbl_add_mac", $labels["LBL_ADD_MAC"]);
    $Skinner->registerVariable("lbl_username", $labels["LBL_USER"]);
    $Skinner->registerVariable("lbl_macaddress", $labels["LBL_MACADDRESS"]);
    $Skinner->registerVariable("user_name_value", $new_user);
    $Skinner->registerVariable("mac_address_value", $new_mac);
    $Skinner->registerVariable("lbl_ok", $labels["LBL_OK"]);
    
    $content=$Skinner->doSubstitution_FAST();
?>
